package com.ayu.scalalearn.chapter06

/**
  * @Author 徐林玉
  * @Description Test10Trait
  * @Date 2022/7/29 14:19
  * @Version 1.0
  */
object Test10Trait {


  def main(args: Array[String]): Unit = {


    //特质如果和主类里面有重复的字段或者方法，需要重写才行
    //Scala 引入 trait 特征，第一可以替代 Java 的接口，第二个也是对单继承机制的一种补充
    val s1: PersonTest10 = new StudentTest10()

    s1.hello()
  }

}

//特质就相当于java的interface
class PersonTest10 {


  val name: String = "ayu"

  var age: Int = 18

  def hello(): Unit = {


    println("Person say hello to you")
  }
}


trait Young {

  val name: String = "young guy"

  var age: Int

  def play(): Unit = {

    println("Young people say hello to you")
  }

  def dating(): Unit
}


class StudentTest10 extends PersonTest10 with Young {

  override val name: String = "stupid student"

  override def dating(): Unit = {

    println("student is dating ")
  }
}
